<?php
namespace Admin\Controller;

// +----------------------------------------------------------------------
// | 文件 PostsController.class.php
// +----------------------------------------------------------------------
// | 说明 帖子控制器
// +----------------------------------------------------------------------
// | 
// +----------------------------------------------------------------------
// | Author: 谢赤心 Legend. <xcx_legender@qq.com>
// +----------------------------------------------------------------------

class PostsController extends BaseManageController {
    /**
    *控制操作的模型表
    */
    protected $modelName = 'Posts'; 

    /**
    *删除类型的设置 true|直接删除， false|设置数据状态
    */
    protected $is_del   = false;

    /**
    *跳转的Url
    */
    // protected $jumpAct  = 'Threads';

    protected $text_map = array(
        'status' => array(0 => '不显示', '1' => '显示'),
        'attachment_type' => ['文字', '图文', '视频'],
    ); // 字符和文字的映射关系



    public function _before_index()
    {
        $threads_id = I('threads_id');
        if (!$threads_id){
            $this->error('缺少threads_id');
        }

        $threads = Service('threads')->find($threads_id);
        $this->assign('threads', $threads);

        $map = array(
            'threads_id'  => $threads_id,
            // 'deleted_at'  => ['$eq' => null],
        );//筛选条件
        $this->where = $map;
        $this->sort = 'floor asc';
    }

    public function format_lists(&$lists) {
        foreach ($lists as $_id => &$item) {
            $item['_id'] = $_id;
            $item['reply_count'] = service('reply')->where(['type' => 3, 'target_id' => $_id])->count();
        }
    }


    public function ajax_reply()
    {
        $posts_id = I('posts_id');
        $replys = service('Reply')->where(['type' => 3, 'target_id' => $posts_id])->order('_id desc')->select();
        $this->assign('replys', $replys);
        echo $this->fetch('ajax_reply');
    }





}